/**
 * 开始启动时候调用的js，用户配置需要引入的js类库
 */
var fileNameSuffix = window.app.mode == "production" ? ".min.js?version=" + window.app.version : ".js?version=" + window.app.version;
//引入模块化编程内容
seajs.config({
	base: "./js/",
	alias: {
		"wechat": "lib/wechat" + fileNameSuffix,
		"template": "lib/template-native.min.js",
		"iscroll": "lib/iscroll-probe.min.js"
	}
});

//下面看看本地是否为初次登录
var isFirstLoginSys = window.localStorage.isFirstLoginSys;
if(window.app.isShowFirstLoginPages && isFirstLoginSys != "true") {
	window.localStorage.isFirstLoginSys = "true";
	window.location.href = "html/fristPage/index.html";
}

//先清除所有storage
window.sessionStorage.clear();

//加载主页面代码
seajs.use("lib/wechat" + fileNameSuffix, function() {
	//取得信息
	var urlParam = common.getURLparams();
	if(window.app.model.toLowerCase() == "debug") {
		$script("js/data.json?version=" + window.app.version, function() {
			//调用初始化函数
			common.hideLoading();
			
			common.loadPage({ pageUrl: "html/index.html" });
		});
	} else {
		var openId = common.getURLparams().wxopenid;
		var appId = common.getURLparams().appid;
		if(!openId){
			openId=common.getURLparams().openid;
		}
		if(openId && appId) {
			window.localStorage.setItem("openId", openId);
			window.localStorage.setItem("appId", appId);
		}else {
				openId = "oZ6swt3KqZdhdl3oBvIqPCBBZI8U";
				appId = "wx0e9a5326968669b3"
				window.localStorage.setItem("openId", "oZ6swt3KqZdhdl3oBvIqPCBBZI8U");
				window.localStorage.setItem("appId", "wx0e9a5326968669b3");
			}
		var type = common.getURLparams().type;
		if(type&& type.length>1) {
			var param = {
				openid: openId,
				appid: appId
			}
			common.loadData({
				url: "/wxmember/service/getWXUserInfoForMenu", 
				param: param,
				successCallBack: function(json) {
					if(json.status == "0") {
						common.loadPage({ pageUrl: "html/"+type+".html" });
					} else {
						common.showTip({
							content: json.message
						});
						common.loadPage({ pageUrl: "html/index.html" });
					}
				}, //回调函数
				dataSource: "getWxUserInfo"
			});
			
		}else {
		
//			var openId = common.getURLparams().wxopenid;
//			var appId = common.getURLparams().appid;
//			if(!openId){
//				openId=common.getURLparams().openid;
//			}
//			if(openId && appId) {
//				window.localStorage.setItem("openId", openId);
//				window.localStorage.setItem("appId", appId);
//			} else {
//				openId = "oZ6swt3KqZdhdl3oBvIqPCBBZI8U";
//				appId = "wx0e9a5326968669b3"
//				window.localStorage.setItem("openId", "oZ6swt3KqZdhdl3oBvIqPCBBZI8U");
//				window.localStorage.setItem("appId", "wx0e9a5326968669b3");
//			}
//			var param = {
//				openId: openId,
//				appId: appId
//			}
//			common.loadData({
//				url: "/wxmember/service/getWxUserInfo", //"/UMPPubServlet?method=getWxUserInfo",
//				param: param,
//				successCallBack: function(json) {
//					if(json.status == "0") {
//						var moblie = json.data.mobile;
////						if(moblie && moblie.length == 11) {
//							window.localStorage.setItem("WxUserInfo", JSON.stringify(json));
							common.loadPage({ pageUrl: "html/index.html" });
//						} else {
//							window.location.href = "#/index/collectCard";
//							common.loadPage({ pageUrl: "html/collectCard.html" });
//						}
//					} else {
//						if(json.code == "notExit") {
//							common.loadPage({ pageUrl: "html/collectCard.html" });
//						} else {
//							window.localStorage.setItem("WxUserInfo", JSON.stringify(json));
//							common.loadPage({ pageUrl: "html/index.html" });
//						}
//					}
//				}, //回调函数
//				dataSource: "getWxUserInfo"
//			});
			//调用初始化函数
		}
	}
});

var amapKey = window.app.amapKey;
//地图需要的js
$script(["http://cache.amap.com/lbs/static/es5.min.js",
	"http://webapi.amap.com/maps?v=1.3&key="+amapKey,
	"http://cache.amap.com/lbs/static/addToolbar.js"
], 'mapJs');